package com.cardbaobao.cardbabyclient.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cardbaobao.cardbabyclient.R;

import java.util.List;


/**
 * 流布局Item通用Adapter 无点击事件 只是展示
 * Created by zad
 * 2016/8/11 14:49
 */

public class FlowCommonAdapter extends BaseAdapter {

    Context context;

    List<String> mData;

    private int layoutId;

    public FlowCommonAdapter(Context context, List<String> mData) {
        this.context = context;
        this.mData = mData;
    }

    public FlowCommonAdapter(Context context, List<String> mData, int layoutId) {
        this.context = context;
        this.mData = mData;
        this.layoutId = layoutId;
    }

    public void setLayoutId(int layoutId){
        this.layoutId = layoutId;
    }

    public void setDatSource(List<String> mData){
        this.mData = mData;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mData==null?0:mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData==null?null:mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(layoutId, null);
            holder = new ViewHolder();
            holder.textView = (TextView) convertView.findViewById(R.id.id_tv_item);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.textView.setText(mData.get(position).toString());
        return convertView;
    }

    class ViewHolder {
        TextView textView;
    }


}
